package com.laiketui.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.laiketui.order.api.enums.DelFlagEnum;
import com.laiketui.order.api.enums.OrderParentMessageType;
import com.laiketui.order.api.enums.OrderStatusEnum;
import com.laiketui.order.domain.OrderMessage;
import com.laiketui.order.domain.OrderParentMessage;
import com.laiketui.order.service.OrderParentMessageService;
import com.laiketui.order.mapper.OrderParentMessageMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
* @author jiangxiang
* @description 针对表【lk_order_parent_message】的数据库操作Service实现
* @createDate 2024-08-20 23:37:55
*/
@Service
public class OrderParentMessageServiceImpl extends ServiceImpl<OrderParentMessageMapper, OrderParentMessage>
    implements OrderParentMessageService{

    @Override
    public OrderParentMessage addOrderParentMessage(String userId,Integer storeId,Integer messageType,String orderParentNo,Integer orderStatus,String messageContent) {
        OrderParentMessage orderParentMessage = new OrderParentMessage();
        orderParentMessage.setCreateBy(userId);
        orderParentMessage.setCreateTime(new Date());
        orderParentMessage.setDeleted(DelFlagEnum.NORMAL.getCode());
        orderParentMessage.setOrderParentNo(orderParentNo);
        orderParentMessage.setOrderStatus(orderStatus);
        orderParentMessage.setMessageType(messageType);
        orderParentMessage.setMessageContent(messageContent);
        orderParentMessage.setStoreId(storeId);
        save(orderParentMessage);
        return orderParentMessage;
    }

    public OrderParentMessage addOrderParentMessageAndPhoto(String userId,Integer storeId,Integer messageType,String orderParentNo,Integer orderStatus,String messageContent,String photo) {
        OrderParentMessage orderParentMessage = new OrderParentMessage();
        orderParentMessage.setCreateBy(userId);
        orderParentMessage.setCreateTime(new Date());
        orderParentMessage.setDeleted(DelFlagEnum.NORMAL.getCode());
        orderParentMessage.setOrderParentNo(orderParentNo);
        orderParentMessage.setOrderStatus(orderStatus);
        orderParentMessage.setMessageType(messageType);
        orderParentMessage.setMessageContent(messageContent);
        orderParentMessage.setStoreId(storeId);
        if(StringUtils.isNotBlank(photo)){
            orderParentMessage.setPhoto(photo);
        }
        save(orderParentMessage);
        return orderParentMessage;
    }

    @Override
    public OrderParentMessage addOrderParentMessageAndPhotoAndRemark(String userId, Integer storeId, Integer messageType, String orderParentNo, Integer orderStatus, String messageContent, String photo, String remark) {
        OrderParentMessage orderParentMessage = new OrderParentMessage();
        orderParentMessage.setCreateBy(userId);
        orderParentMessage.setCreateTime(new Date());
        orderParentMessage.setDeleted(DelFlagEnum.NORMAL.getCode());
        orderParentMessage.setOrderParentNo(orderParentNo);
        orderParentMessage.setOrderStatus(orderStatus);
        orderParentMessage.setMessageType(messageType);
        orderParentMessage.setMessageContent(messageContent);
        orderParentMessage.setStoreId(storeId);
        if(StringUtils.isNotBlank(photo)){
            orderParentMessage.setPhoto(photo);
        }
        if(StringUtils.isNotBlank(remark)){
            orderParentMessage.setRemark(remark);
        }
        save(orderParentMessage);
        return orderParentMessage;
    }

    @Override
    public List<OrderParentMessage> findByOrderParentNo(String orderParentNo) {
        LambdaQueryWrapper<OrderParentMessage> wrapper=new LambdaQueryWrapper<OrderParentMessage>();
        wrapper.eq(OrderParentMessage::getOrderParentNo,orderParentNo);
        return list(wrapper);
    }

    @Override
    public List<OrderParentMessage> listByOrderParentNo(String orderParentNo) {
        if(StringUtils.isBlank(orderParentNo)){
            return Collections.emptyList();
        }
        LambdaQueryWrapper<OrderParentMessage> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(OrderParentMessage::getOrderParentNo, orderParentNo);
        wrapper.eq(OrderParentMessage::getDeleted, DelFlagEnum.NORMAL.getCode());
        wrapper.orderByDesc(OrderParentMessage::getId);
        return list(wrapper);
    }
}




